package cn.yeziji.file.handler.channel;

import cn.yeziji.forum.basic.file.WebUploader;
import cn.yeziji.file.handler.service.TypeSelected;
import cn.yeziji.file.service.InteractionService;
import cn.yeziji.forum.basic.file.WebUploaderFileEntity;
import cn.yeziji.forum.utils.SpringUtils;

/**
 * 公共文件操作
 *
 * @author gzkemays
 * @since 2022/11/04 12:18 AM
 */
public class CommonHandler extends FileTypeHandler {
  InteractionService interactionService;

  public CommonHandler(TypeSelected selected) {
    super(selected);
    this.interactionService = SpringUtils.getBean(InteractionService.class);
  }

  @Override
  public void handler(WebUploader.ChuckEntity entity) {
    Object scope = typeHandler.types(entity.getOriginalFilename());
    interactionService.save(
        new WebUploaderFileEntity(
            scope.toString(),
            entity.getUploaderMd5(),
            entity.getUsername(),
            entity.getDesc(),
            entity.getSize(),
            null));
  }
}
